package department.fc.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class SearchDepartmentController implements Controller{

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
//		1. 요청 파라미터 조회 
		String location = request.getParameter("location");
//		2. 비즈니스 로직 처리
		AttributeAndView av = null;
		DepartmentService service = DepartmentService.getInstance();
		try {
			ArrayList<Department> list = service.searchDepartmentByLocation(location);
			
			HashMap<String, Object> attr = new HashMap<String, Object>();
			attr.put("departmentList", list);
			attr.put("searchLabel", "지점으로 검색한 결과");
			attr.put("searchKeyword", "검색 키워드 : "+location);
			av = new AttributeAndView(false,"/WEB-INF/jsp/dept/department_list.jsp", attr);
		} catch (SQLException e) {
			e.printStackTrace();
			av = new AttributeAndView(false, "/WEB-INF/jsp/error.jsp", "error_message",e.getMessage());
		}
		return av;
	}

}
